// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "Modules/BuildVersion.h"

/**
 * Record of a file that was created as part of the build process
 */
struct FBuildProduct
{
	/** Path to the file. */
	FString Path;

	/** Type of the build product. */
	FString Type;
};

/** 
 * Information about a file which is required by the target at runtime, and must be moved around with it.
 */
struct FRuntimeDependency
{
	/** The file that should be staged. Should use $(EngineDir) and $(ProjectDir) variables as a root, so that the target can be relocated to different machines. */
	FString Path;

	/** How to stage this file. */
	FString Type;
};

/**
 * Arbitrary property name/value which metadata from the build scripts can be passed on to downstream tasks
 */
struct FReceiptProperty
{	
	/** Property name */
	FString Name;

	/** Value of the property */
	FString Value;
};

/**
 * Stores information about a compiled target. Mirror of the TargetReceipt class generated by UBT.
 */
struct  FTargetReceipt
{
	/** Path to the project file for this target */
	FString ProjectFile;

	/** The project directory */
	FString ProjectDir;

	/** The name of this target */
	FString TargetName;

	/** Which platform the target is compiled for */
	FString Platform;

	/** Which platform the target is compiled for */
	FString Architecture;

	/** Which configuration this target is compiled in */
	EBuildConfiguration Configuration;

	/** The type of the target */
	EBuildTargetType TargetType;

	/** The version information for this target */
	FBuildVersion Version;

	/** The exectuable to launch for this target */
	FString Launch;

	/** The build products which are part of this target */
	TArray<FBuildProduct> BuildProducts;

	/** All the runtime dependencies that this target relies on */
	TArray<FRuntimeDependency> RuntimeDependencies;

	/** Additional build properties passed through from the module rules */
	TArray<FReceiptProperty> AdditionalProperties;

	/**
	 * Read a target receipt from disk
	 *
	 * @param FileName The file to read from
	 * @return True if the file was read successfully
	 */
	bool Read(const FString& FileName);

	/**
	 * Gets the default path for a target receipt
	 *
	 * @param BaseDir Base directory for the target being built; either the project directory or engine directory.
	 * @param TargetName The target being built
	 * @param Platform The target platform
	 * @param Configuration The target configuration
	 * @param BuildArchitecture The architecture being built
	 * @return Path to the receipt for this target
	 */
	static FString GetDefaultPath(const TCHAR* BaseDir, const TCHAR* TargetName, const TCHAR* Platform, EBuildConfiguration Configuration, const TCHAR* BuildArchitecture);

private:
	/**
	 * Expands the $(EngineDir) and $(ProjectDir) variables within a string
	 *
	 * @param Path Path to expand variables within
	 */
	void ExpandVariables(FString& Path);
};
